import ReactDOM from "react-dom";
const renderKey = {};

export const isServer = typeof window === 'undefined';

export const getClassName = pathname => {
	let path = "";
	if (pathname) {
		pathname = pathname.replace(/\?.*/, "");
		path = pathname.split("/").pop();
		return "class-" + path;
	}
	return null;
};

export const createPortal = reactElement => {
	let className = getClassName(location.hash.slice(1));
	const key = reactElement.key;

	if (key) {
		let renderClass = renderKey[key];
		if (renderClass) {
			if (renderClass !== className) {
				return;
			}
		} else {
			renderKey[key] = className;
		}
	}
	let dom = null;
	if (className) {
		dom = document.querySelector("." + className) || document.body;
	} else {
		dom = document.body;
	}
	return ReactDOM.createPortal(reactElement, dom);
};
export const billReportUrl = () => {
	let url = "";
	if (process.env.ENV_CONFIG === "test") {
		url = "https://huikaidian-sit.yonghui.cn/apph5/activity/#/billReport";
	} else if (process.env.ENV_CONFIG === "dev") {
		url = "http://10.10.234.26:8081/#/billReport";
	} else if (process.env.ENV_CONFIG === "prod") {
		url =
			"https://jrcdn.yonghui.cn/yhjr/yhjrActivity/xhf/index.html#/billReport";
	}
	return url;
};
export const redRainUrl = () => {
	let url = "";
	if (process.env.ENV_CONFIG === "test") {
		url = "https://huikaidian-sit.yonghui.cn/apph5/activity/#/redPacket";
	} else if (process.env.ENV_CONFIG === "dev") {
		url = "http://10.10.234.26:8081/#/redPacket";
	} else if (process.env.ENV_CONFIG === "prod") {
		url =
			"https://jrcdn.yonghui.cn/yhjr/yhjrActivity/xhf/index.html#/redPacket";
	}
	return url;
};
